

UIManager={};
function LuaMain()




  

    UIManager.CreatARcanerUI();


end

VideoButton2State=false;
PhotoButton2State=false;

VideoStart=false;


lastTime = 0;
curTime=0;
UI_ARCamer={
    Distinguish=nil, --扫描
    CameraButton=nil,
    FlashOffButton=nil,
    FlashAutoButton=nil,
    FlashOnButton=nil,
    VideoButton=nil,
    AboutButton=nil,
    PhotoButton=nil,
    VideoButton2=nil,
    PhotoButton2=nil,
    Tips=nil,
    VideoTime=nil,
    Image=nil,
    SpotImage=nil,
    VideoButton3=nil,
};

UI_ARCamerbutton=nil;

UI_About={
    Button1=nil,
    Button2=nil,
    Text1=nil,
    Text2=nil,
    BackButton=nil,
};

UIManager.CreatARcanerUI=function()



   obj3= self:FindObj("3");
   self:Lod_log("CreatARcanerUI")
   --print(obj3.name);
---绑定视频播放完成会掉

self:Setjomp_Spto(jomp_Spto);
  
    local ab=self.assetBudleManager:GetAssetBundle("ui","ui/arcamer");
	ARcamerUI = CS.UnityEngine.Object.Instantiate(ab:LoadAsset("arcamer").gameObject).gameObject;
	ARcamerUI.transform:SetParent(self.transform);
	self.objectManager:AddModularGameObject("ARcamer",ARcamerUI);
	local ARcamerUITransform=ARcamerUI:GetComponent("RectTransform");
	ARcamerUITransform.localScale=CS.UnityEngine.Vector3.one;
	ARcamerUITransform.sizeDelta=CS.UnityEngine.Vector2(0,0);
    ARcamerUITransform.localPosition=CS.UnityEngine.Vector3.zero;   
    ARcamerUITransform:SetSiblingIndex(1);
    ARcamerUI:SetActive(false);
    UI_ARCamer.Distinguish=self.objectManager:fandGameobject("ARcamer","Distinguish");

    UI_ARCamer.CameraButton=self.objectManager:fandGameobject("ARcamer","CameraButton");
    UI_ARCamer.CameraButton:GetComponent("Button").onClick:AddListener(OnCameraButtonClick);

    UI_ARCamer.FlashOffButton=self.objectManager:fandGameobject("ARcamer","FlashOffButton");
    UI_ARCamer.FlashOffButton:GetComponent("Button").onClick:AddListener(OnFlashOffButtonClick);

    UI_ARCamer.FlashAutoButton=self.objectManager:fandGameobject("ARcamer","FlashAutoButton");
    UI_ARCamer.FlashAutoButton:GetComponent("Button").onClick:AddListener(OnFFlashAutoButtonClick);

    UI_ARCamer.FlashOnButton=self.objectManager:fandGameobject("ARcamer","FlashOnButton");
    UI_ARCamer.FlashOnButton:GetComponent("Button").onClick:AddListener(OnFlashOnButtonClick);

    UI_ARCamer.VideoButton=self.objectManager:fandGameobject("ARcamer","VideoButton");
    UI_ARCamer.VideoButton:GetComponent("Button").onClick:AddListener(OnVideoButtonClick);
    UI_ARCamer.VideoButton:SetActive(false);
    UI_ARCamer.AboutButton=self.objectManager:fandGameobject("ARcamer","AboutButton");
    UI_ARCamer.AboutButton:GetComponent("Button").onClick:AddListener(OnAboutButtonClick);

    UI_ARCamer.PhotoButton=self.objectManager:fandGameobject("ARcamer","PhotoButton");
    UI_ARCamer.PhotoButton:GetComponent("Button").onClick:AddListener(OnPhotoButtonClick);
    UI_ARCamer.PhotoButton:SetActive(true);
    UI_ARCamer.VideoButton2=self.objectManager:fandGameobject("ARcamer","VideoButton2");
    UI_ARCamer.VideoButton2:GetComponent("Button").onClick:AddListener(OnVideoButtonClick2);

    UI_ARCamer.PhotoButton2=self.objectManager:fandGameobject("ARcamer","PhotoButton2");
    UI_ARCamer.PhotoButton2:GetComponent("Button").onClick:AddListener(OnPhotoButtonClick2);
    
    UI_ARCamer.Image=self.objectManager:fandGameobject("ARcamer","Image");
    UI_ARCamer.SpotImage=self.objectManager:fandGameobject("ARcamer","SpotImage");

    UI_ARCamer.Tips=self.objectManager:fandGameobject("ARcamer","Tips");
    UI_ARCamer.Tips:SetActive(false);
    UI_ARCamer.VideoTime=self.objectManager:fandGameobject("ARcamer","VideoTime");
    UI_ARCamer.VideoTime:SetActive(false);
    Scan=self.objectManager:fandGameobject("ARcamer","Scan");
    Scan:SetActive(false);
    UI_ARCamer.VideoButton3=self.objectManager:fandGameobject("ARcamer","PhotoButton (1)");
    UI_ARCamer.VideoButton3:GetComponent("Button").onClick:AddListener(OnPhotoButtonClick);

    UI_ARCamer.VideoButton3:SetActive(false);
    Button1000=self.objectManager:fandGameobject("ARcamer","Button (1)");
    Button1000:SetActive(false);



---加载教程ui



    local ab=self.assetBudleManager:GetAssetBundle("ui","ui/course");
	Course = CS.UnityEngine.Object.Instantiate(ab:LoadAsset("course").gameObject).gameObject;
	Course.transform:SetParent(self.transform);
	self.objectManager:AddModularGameObject("Course",Course);
	local CourseTransform=Course:GetComponent("RectTransform");
	CourseTransform.localScale=CS.UnityEngine.Vector3.one;
	CourseTransform.sizeDelta=CS.UnityEngine.Vector2(0,0);
    CourseTransform.localPosition=CS.UnityEngine.Vector3.zero;   
    CourseTransform:SetSiblingIndex(1);
    Course:SetActive(true);
    CourseButton=self.objectManager:fandGameobject("Course","Button");
    CourseButton:GetComponent("Button").onClick:AddListener(function() 
        Course:SetActive(false);
        ARcamerUI:SetActive(true);
        self:SetString("Name","null");
    end);
    jiaocheng=self:GetString("Name");
    if (jiaocheng=="null")then

       
        Course:SetActive(false);
        ARcamerUI:SetActive(true);
        UI_ARCamer.VideoTime:SetActive(false);
  
    else


    end
isStartPhtot=false;
   OnPhotoButtonClick2();
    
     ab=self.assetBudleManager:GetAssetBundle("ui","ui/about");
     AboutUI = CS.UnityEngine.Object.Instantiate(ab:LoadAsset("about").gameObject).gameObject;
     AboutUI.transform:SetParent(self.transform);
	self.objectManager:AddModularGameObject("About",AboutUI);
	local AboutUITransform=AboutUI:GetComponent("RectTransform");
	AboutUITransform.localScale=CS.UnityEngine.Vector3.one;
	AboutUITransform.sizeDelta=CS.UnityEngine.Vector2(0,0);
    AboutUITransform.localPosition=CS.UnityEngine.Vector3.zero;   
    AboutUITransform:SetSiblingIndex(1);
    AboutUI:SetActive(false);

    UI_About.BackButton=self.objectManager:fandGameobject("About","BackButton");
    UI_About.BackButton:GetComponent("Button").onClick:AddListener(OnAbout_BackButtonClick);

    UI_About.Button2=self.objectManager:fandGameobject("About","Button2");
    UI_About.Button2:GetComponent("Button").onClick:AddListener(function() 
         obj3:SetActive(false);
        obj3:SetActive(true);
        SetPromptUI(isUpdate_PromptBack,"确 定",false,"缓存清除完成！！！") end);

    UI_About.Button1=self.objectManager:fandGameobject("About","Button1");
    UI_About.Button1:GetComponent("Button").onClick:AddListener(function() 
        obj3:SetActive(false);
        obj3:SetActive(true);
        self:InvokeFOLua(function() 
            CS.UnityEngine.Application.OpenURL("http://www.xiaomayunkeji.com"); 
        end,1);
         
        end);



    UI_About.Text1=self.objectManager:fandGameobject("About","Text1");
    text=UI_About.Text1:GetComponent("Text");
    text.lineSpacing=1;


--请求 ar配置


    self:GetARConfig("http://arapi.xiaomayunkeji.com/ar/getConfig",ARconfigBack);

    mainloadui:SetActive(false);
 UI_ARCamer.FlashAutoButton:SetActive(false);
UI_ARCamer.FlashOffButton:SetActive(true);
UI_ARCamer.FlashOnButton:SetActive(false);


--临时按钮
tmpFlashButton = UI_ARCamer.FlashOffButton;
end



function ARconfigBack(jd)

    print("--"..jd)
     t12 = rapidjson.decode(jd)
     print("--"..t12.Error);
    if(t12.Error=='null') then
     
        local s = rapidjson.encode(t12.Text)
        jsonC = rapidjson.decode(s)
           
        for i, v in ipairs(jsonC.video) do
            local mapName=v.mapName;
            print("--"..v.mapName.."--"..v.name.."---"..v.videoHttp);
            SetARImageTargetVideo(v.mapName,v.name,v.videoHttp,v.isChroam,v.isJump,v.jumpHttp);
        end  
    
        for i, v in ipairs(jsonC.model) do
            local mapName=v.mapName;
            SetARImageTarget(v.mapName,v.name,v.modelName);
        end  
	else 
		SetPromptUI(isUpdate_PromptBack,"确 定",false,"访问服务器错误！请重启")
	end
end
--加载 支持 识别模型
function SetARImageTarget(url,name,modelName)


    ImageTarget = self:loadARImageTarget(url,name);
    objCube=ImageTarget.transform:Find("Cube").gameObject;
    objCube:SetActive(false);
    local ab=self.assetBudleManager:GetAssetBundle("model","model/"..modelName);
    if (ab~=nil) then
        seadrago = CS.UnityEngine.Object.Instantiate(ab:LoadAsset(modelName).gameObject).gameObject;
        seadrago.transform:SetParent(ImageTarget.transform);
        seadrago.transform.localPosition=CS.UnityEngine.Vector3(0,0,0);
        seadrago.transform.localScale=CS.UnityEngine.Vector3(1,1,1);
    end
end
--加载 支持 播放 非透明视频
function SetARImageTargetVideo(url,namen,http,islv,isToR,toUrl)


    ImageTarget = self:loadImageTargetVideo(url,namen,http,islv,isToR,toUrl);


end


CameraFront=false;
--切换摄像头

function OnCameraButtonClick()  

    obj3:SetActive(false);
    obj3:SetActive(true);
    if(CameraFront==false)then
        self.aRcameraManager:OpenCameraFront();
        CameraFront=true;
        return;
    end
    self.aRcameraManager:OpenCameraBack();
    CameraFront=false;
    print("OnCameraButtonClick");
end
IsFlash=false;

isShwoUI=false;





--关闭闪光灯
function OnFlashOffButtonClick()  

  
    if(isShwoUI==false)then
        isShwoUI=true;
        UI_ARCamer.FlashAutoButton:SetActive(true);
        UI_ARCamer.FlashOffButton:SetActive(true);
        UI_ARCamer.FlashOnButton:SetActive(true);
        obj3:SetActive(false);
        obj3:SetActive(true);
    else

        UI_ARCamer.FlashOffButton:SetActive(true);
        --获取上次选择按钮的位置
       tmpT2= UI_ARCamer.FlashOffButton:GetComponent("RectTransform");
       tmpTv= UI_ARCamer.FlashOffButton:GetComponent("RectTransform").localPosition;

       tmpT3= tmpFlashButton:GetComponent("RectTransform");

       tmpT2.localPosition=CS.UnityEngine.Vector3(tmpT3.localPosition.x,tmpT3.localPosition.y,tmpT3.localPosition.z);

       tmpT3.localPosition=CS.UnityEngine.Vector3(tmpTv.x,tmpTv.y,tmpTv.z);
        tmpFlashButton=UI_ARCamer.FlashOffButton
  
        isShwoUI=false;
        UI_ARCamer.FlashAutoButton:SetActive(false);
        UI_ARCamer.FlashOnButton:SetActive(false);

        self.aRcameraManager:stopFlash();
        IsFlash=false;
    end



end
--自动

function OnFFlashAutoButtonClick()
    print("OnFFlashAutoButtonClick");



    if(isShwoUI==false)then
        isShwoUI=true;
        UI_ARCamer.FlashAutoButton:SetActive(true);
        UI_ARCamer.FlashOffButton:SetActive(true);
        UI_ARCamer.FlashOnButton:SetActive(true);
        obj3:SetActive(false);
        obj3:SetActive(true);
    else

        UI_ARCamer.FlashAutoButton:SetActive(true);
    
       tmpT2= UI_ARCamer.FlashAutoButton:GetComponent("RectTransform");
       tmpTv= UI_ARCamer.FlashAutoButton:GetComponent("RectTransform").localPosition;

       tmpT3= tmpFlashButton:GetComponent("RectTransform");

       tmpT2.localPosition=CS.UnityEngine.Vector3(tmpT3.localPosition.x,tmpT3.localPosition.y,tmpT3.localPosition.z);

       tmpT3.localPosition=CS.UnityEngine.Vector3(tmpTv.x,tmpTv.y,tmpTv.z);
        tmpFlashButton=UI_ARCamer.FlashAutoButton
  
        isShwoUI=false;
        UI_ARCamer.FlashOnButton:SetActive(false);
        UI_ARCamer.FlashOffButton:SetActive(false);
        self.aRcameraManager:stopFlash();
        IsFlash=true;
    end

    
end
--开启闪光灯
function OnFlashOnButtonClick()
    
    print("OnFlashOnButtonClick");

    if(isShwoUI==false)then
        isShwoUI=true;
        UI_ARCamer.FlashAutoButton:SetActive(true);
        UI_ARCamer.FlashOffButton:SetActive(true);
        UI_ARCamer.FlashOnButton:SetActive(true);
        obj3:SetActive(false);
        obj3:SetActive(true);
    else

        UI_ARCamer.FlashOnButton:SetActive(true);
 
       tmpT2= UI_ARCamer.FlashOnButton:GetComponent("RectTransform");
       tmpTv= UI_ARCamer.FlashOnButton:GetComponent("RectTransform").localPosition;

       tmpT3= tmpFlashButton:GetComponent("RectTransform");

       tmpT2.localPosition=CS.UnityEngine.Vector3(tmpT3.localPosition.x,tmpT3.localPosition.y,tmpT3.localPosition.z);

       tmpT3.localPosition=CS.UnityEngine.Vector3(tmpTv.x,tmpTv.y,tmpTv.z);
        tmpFlashButton=UI_ARCamer.FlashOnButton
  
        isShwoUI=false;
        UI_ARCamer.FlashAutoButton:SetActive(false);
        UI_ARCamer.FlashOffButton:SetActive(false);
        self.aRcameraManager:startFlash();
        IsFlash=false;
    end

end
--录像暂停
function OnVideoButtonClick()
    print("OnVideoButtonClick");
    if(second>1) then
        StopRecord();
        return;
    end
    
end
--关于
function OnAboutButtonClick()
    print("OnAboutButtonClick");
    self.aRcameraManager:StopCapture();
    ARcamerUI:SetActive(false);
    AboutUI:SetActive(true);
    obj3:SetActive(false);
    obj3:SetActive(true);
end
function OnAbout_BackButtonClick()

   
    obj3:SetActive(false);
    obj3:SetActive(true);
    self.aRcameraManager:StartCapture();
    ARcamerUI:SetActive(true);
    AboutUI:SetActive(false);
    
end
--拍照 录像 按钮
function OnPhotoButtonClick()
    if (VideoButton2State==false) then
       
        self:PlayAudio(ARcamerUI);
        for k, v in pairs(UI_ARCamer) do
            v:SetActive(false);
           
        end
        UI_ARCamer.Image:SetActive(true);
        if(IsFlash==true) then
            self.aRcameraManager:startFlash();
        end
    self.aRcameraManager:OnClickTakePicturesButton(
            function(s) 
                for k, v in pairs(UI_ARCamer) do
                    v:SetActive(true);
                    UI_ARCamer.VideoTime:SetActive(false);
                    UI_ARCamer.VideoButton3:SetActive(false);
                    UI_ARCamer.FlashAutoButton:SetActive(false);
                    UI_ARCamer.FlashOffButton:SetActive(false);
                    UI_ARCamer.FlashOnButton:SetActive(false);
                    tmpFlashButton:SetActive(true);
                end
                self:InvokeFOLua(function() 
                    UI_ARCamer.VideoTime:SetActive(false);
                    UI_ARCamer.Tips:SetActive(false);
                    UI_ARCamer.VideoButton:SetActive(false);
                    UI_ARCamer.Image:SetActive(false);
                end,2);
                self.aRcameraManager:stopFlash();
            end);
    end
    if (VideoButton2State==true) then
        UI_ARCamer.VideoButton:SetActive(true);
        if(VideoStart==false) then
            VideoStart=true;
            self.aRcameraManager:StartRecord();
            lastTime=CS.UnityEngine.Time.time;
            UI_ARCamer.VideoTime:SetActive(true);
            UI_ARCamer.VideoButton3:SetActive(false);
            UI_ARCamer.VideoButton2:SetActive(false);
            UI_ARCamer.PhotoButton2:SetActive(false);
            UI_ARCamer.AboutButton:SetActive(false);
            UI_ARCamer.Distinguish:SetActive(false);
            UI_ARCamer.CameraButton:SetActive(false);
            UI_ARCamer.FlashAutoButton:SetActive(false);
            UI_ARCamer.FlashOffButton:SetActive(false);
            UI_ARCamer.FlashOnButton:SetActive(false);
            UI_ARCamer.SpotImage:SetActive(false);
         else
            StopRecord();
        end
    end

    print("OnPhotoButtonClick");
end



Video2V3off=CS.UnityEngine.Vector3(-67,-271,0);
Video2V3on=CS.UnityEngine.Vector3(0.5,-271,0);

Photo2V3off=CS.UnityEngine.Vector3(67,-271,0);
Photo2V3on=CS.UnityEngine.Vector3(0.5,-271,0);

function OnVideoButtonClick2()
    print("OnVideoButtonClick2");
    AVideoButton2Transform=UI_ARCamer.VideoButton2:GetComponent("RectTransform");
    PhotoButton2Transform=UI_ARCamer.PhotoButton2:GetComponent("RectTransform");
    obj3:SetActive(false);
    obj3:SetActive(true);
    if (VideoButton2State==false) then
        y=AVideoButton2Transform.localPosition.y;
        AVideoButton2Transform.localPosition=CS.UnityEngine.Vector3(0.5,y,0);
        y1=PhotoButton2Transform.localPosition.y;
        PhotoButton2Transform.localPosition=CS.UnityEngine.Vector3(67,y1,0);
 
        
        UI_ARCamer.VideoButton3:SetActive(true);
        UI_ARCamer.PhotoButton:SetActive(false);
        VideoButton2State=true;
        PhotoButton2State=false;

    end
    
end
function OnPhotoButtonClick2()
    print("OnPhotoButtonClick2");
    if(isStartPhtot==true) then
        obj3:SetActive(false);
        obj3:SetActive(true);
    end
    isStartPhtot=true;
    if (VideoStart==false)then
        AVideoButton2Transform=UI_ARCamer.VideoButton2:GetComponent("RectTransform");
        PhotoButton2Transform=UI_ARCamer.PhotoButton2:GetComponent("RectTransform");
        if (PhotoButton2State==false)then

            y=AVideoButton2Transform.localPosition.y;
            AVideoButton2Transform.localPosition=CS.UnityEngine.Vector3(-67,y,0);
            y1=PhotoButton2Transform.localPosition.y;
            PhotoButton2Transform.localPosition=CS.UnityEngine.Vector3(0.5,y1,0);
           -- UI_ARCamer.PhotoButton:GetComponent("Image").color=CS.UnityEngine.Color.white
            PhotoButton2State=true;
            VideoButton2State=false;
            UI_ARCamer.VideoButton3:SetActive(false);
            UI_ARCamer.PhotoButton:SetActive(true);
        end
    end     
end


vtime=0;
Minute=0;
second=0;
function MonoUpdate()
    if (VideoStart==true) then
        curTime = CS.UnityEngine.Time.time;
        if (curTime - lastTime >= 1) then
            second=second+1;
          
                UI_ARCamer.VideoTime:GetComponent("Text").text=Minute..":0"..second;
            if(second>9) then
                UI_ARCamer.VideoTime:GetComponent("Text").text=Minute..":"..second;
            end
            if(second>59) then
                Minute=Minute+1;
                second=0;
                UI_ARCamer.VideoTime:GetComponent("Text").text=Minute..":"..second;
            end
            lastTime = curTime;
            if(second==15) then
                --StopRecord();
            end
        end

    end
end
function StopRecord()

    vtime=0;
    Minute=0;
second=0;
    UI_ARCamer.Tips:SetActive(true);
    self:InvokeFOLua(function() 

        UI_ARCamer.Tips:SetActive(false);
       
    end,2);

    VideoStart=false;
    UI_ARCamer.VideoButton3:SetActive(true);
    UI_ARCamer.VideoTime:SetActive(false);
    UI_ARCamer.VideoButton2:SetActive(true);
    UI_ARCamer.PhotoButton2:SetActive(true);
    UI_ARCamer.AboutButton:SetActive(true);
    UI_ARCamer.Distinguish:SetActive(true);
    UI_ARCamer.CameraButton:SetActive(true);
    UI_ARCamer.FlashAutoButton:SetActive(false);
    UI_ARCamer.FlashOffButton:SetActive(false);
    UI_ARCamer.FlashOnButton:SetActive(false);
    tmpFlashButton:SetActive(true);
    UI_ARCamer.SpotImage:SetActive(true);
    self.aRcameraManager:StopRecord();
    UI_ARCamer.VideoTime:GetComponent("Text").text="0:00";
end

function jomp_Spto()
    if(VideoStart==true) then
         StopRecord();
    end
end
